import store from '@/store'

export default {
  inserted(el, binding, vnode) {
    const { value } = binding
    const modelIds = store.getters && store.getters.modelIds
    // const modelId = store.getters && store.getters.modelId

    // if (value && value instanceof Array && value.length > 0) {
    if (value && modelIds && modelIds.length > 0) {
      const modelId = value

      
      const hasPermission = modelIds.includes(modelId);
      // const hasPermission = modelIds.some(modelId => {
      //   return permissionRoles.includes(modelId)
      // })
      
      if (!hasPermission) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      // throw new Error(`need roles! Like v-permission="['admin','editor']"`)
      throw new Error(`v-permission：value和modelIds不能为空`)
    }
  }
}
